﻿Imports CapaEntidadesNegocio
Imports System.Data.SqlClient

Public Class MarcaAD

    Private conn As SqlConnection
    Private comando As New SqlCommand
    Private obj As BancoEN


    Public Sub New()

        Dim objConexion As New Conexion
        conn = objConexion.abrir
        comando.Connection = conn

    End Sub

    Public Sub insertar(ByVal objMarcaEN As MarcaEN)


        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_marca_i"

        Dim pNombre As New SqlParameter("@nombre", SqlDbType.VarChar)
        pNombre.Value = objMarcaEN._nombre
        pNombre.Direction = ParameterDirection.Input
        comando.Parameters.Add(pNombre)



        comando.ExecuteNonQuery()
        comando.Parameters.Clear()





    End Sub


    Public Sub eliminar(ByVal objMarcaEN As MarcaEN)


        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_marca_d"

        Dim pId As New SqlParameter("@idMarca", SqlDbType.Int)
        pId.Value = objMarcaEN._idMarca
        pId.Direction = ParameterDirection.Input
        comando.Parameters.Add(pId)



        comando.ExecuteNonQuery()
        comando.Parameters.Clear()





    End Sub

    Public Sub modificar(ByVal objMarcaEN As MarcaEN)


        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_marca_u"

        Dim pNombre As New SqlParameter("@nombre", SqlDbType.VarChar)
        pNombre.Value = objMarcaEN._nombre
        pNombre.Direction = ParameterDirection.Input
        comando.Parameters.Add(pNombre)

        Dim pId As New SqlParameter("@idMarca", SqlDbType.Int)
        pId.Value = objMarcaEN._idMarca
        pId.Direction = ParameterDirection.Input
        comando.Parameters.Add(pId)




        comando.ExecuteNonQuery()
        comando.Parameters.Clear()



    End Sub


    Public Function consultar() As List(Of MarcaEN)

        Dim objMarcaEN As MarcaEN
        Dim lstobjMarcaEN As List(Of MarcaEN)

        lstobjMarcaEN = New List(Of MarcaEN)

        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_marca_s"




        Dim reader As SqlDataReader = comando.ExecuteReader()

        If reader.HasRows Then
            While reader.Read()

                objMarcaEN = New MarcaEN

                objMarcaEN._idMarca = reader("idMarca")
                objMarcaEN._nombre = reader("nombre")

                lstobjMarcaEN.Add(objMarcaEN)

            End While

        End If


        reader.Close()
        comando.Parameters.Clear()
        Return lstobjMarcaEN



    End Function



End Class
